var SolarTerms = angular.module("SolarTerms");

SolarTerms.service('drawPic',function(){

})
    .service("paginateSer", ['$timeout', '$rootScope',function ($timeout, $rootScope) {
        this.paginate = {
            total: '',//共多少条
            pageSize: '',//每页多少条
            pageNum: '',//当前第几页从1~
            pageS: '',//页数
            myArr: [{name: this.total}, {name: "上一页", value: "pre"}, {name: "下一页", value: "next"}],//关键 页面上的所有分页按钮都由此数组而来
            init: function (total, pageSize, pageNum) {
                this.myArr = [{name: this.total}, {name: "上一页", value: "pre"}, {
                    name: "下一页",
                    value: "next"
                }];

                this.myArr[0].name = "总共 " + total + " 条";
                this.total = total;
                this.pageSize = pageSize;
                this.pageNum = pageNum;
                //this.itemId=itemId;
                this.pageS = Math.ceil(total / this.pageSize);
                //console.log(this);
                if (this.pageS <= 8 && this.pageS > 0) {
                    for (var i = 1; i <= this.pageS; i++) {
                        this.myArr.splice(i + 1, 0, {
                            name: i,
                            value: i,
                            className: this.pageNum == i ? 'active' : null
                        });
                    }
                }
                else if (this.pageS > 8) {
                    if (this.pageNum <= 3) {
                        this.myArr.splice(2, 0, {
                            name: 1,
                            value: 1,
                            className: this.pageNum == 1 ? "active" : ""
                        }, {name: 2, value: 2, className: this.pageNum == 2 ? "active" : ""}, {
                            name: 3,
                            value: 3, className: this.pageNum == 3 ? "active" : ""
                        }, {name: "..."}, {
                            name: this.pageS,
                            value: this.pageS
                        });
                    } else if (this.pageNum >= 4 && this.pageNum <= this.pageS - 1) {
                        this.myArr.splice(2, 0,
                            {name: 1, value: 1}
                            , {name: 2, value: 2}
                            , {name: 3, value: 3}
                            , this.pageNum <= 5 ? null : {name: "..."}
                            , this.pageNum >= this.pageS - 2 ? {name: this.pageNum - 2, value: this.pageNum - 2} : null
                            , this.pageNum > 4 ? {name: this.pageNum - 1, value: this.pageNum - 1} : null
                            , {name: this.pageNum, value: this.pageNum, className: "active"}
                            , this.pageNum == this.pageS - 1 ? null : {name: this.pageNum + 1, value: this.pageNum + 1}
                            , this.pageNum == this.pageS - 1 || this.pageNum == this.pageS - 2 ? null : {name: "..."}
                            , {name: this.pageS, value: this.pageS});

                    } else if (this.pageNum == this.pageS) {
                        this.myArr.splice(2, 0
                            , {name: 1, value: 1}
                            , {name: 2, value: 2}
                            , {name: 3, value: 3}
                            , {name: "..."}
                            , {name: this.pageS - 2, value: this.pageS - 2}
                            , {name: this.pageS - 1, value: this.pageS - 1}
                            , {name: this.pageS, value: this.pageS, className: "active"});
                    }
                }
                for (var i = 0; i < this.myArr.length; i++) {
                    if (this.myArr[i] == null) {
                        this.myArr.splice(i--, 1);
                    }
                }
                this.myArr[1].className = this.pageNum == 1 || this.total == 0 ? "disabled" : "";
                this.myArr[this.myArr.length - 1].className = this.pageNum == this.pageS || this.total == 0 ? "disabled" : "";

            },//页面载入即刷新myArr和paginateSer服务
            whereGo: function (pn) {//页面载入即刷新myArr以及跳转
                var _self = this;
                //console.log(pn);
                if (_self.total == 0) {
                    return null;
                }
                if (pn == "next") {
                    if (_self.pageNum == _self.pageS) {
                        return null;
                    }
                    _self.pageNum++;
                } else if (pn == "pre") {
                    if (_self.pageNum == 1) {
                        return null;
                    }
                    _self.pageNum--;
                } else if (pn != null && pn != undefined) {
                    if (_self.pageNum == pn) {
                        return null;
                    }
                    _self.pageNum = pn;
                } else {
                    return null;
                }
                $rootScope.pageNum= _self.pageNum;
                //console.log(this.myArr);
                _self.promise(_self);
            },//按钮
            promise: function () {
            }
        };
    }])//新闻列表 分页

    .constant('config',{
        appCode:'http://106.14.253.245/',
        billSearch: 'logistics/info.json?orderNo=',//运单查询
        getNews: 'news/getNews.json',//新闻列表
        getNewsById: 'news/getNewsById.json' ,//新闻内容
        regNum12:/^[0-9]{12}$/,
        localUrl:'',
        localTitle:'臻程物流'
    })



;

